package com.example.accessibilityhelper.group

import android.accessibilityservice.AccessibilityService
import android.view.accessibility.AccessibilityEvent
import com.example.accessibilityhelper.Step
import com.example.accessibilityhelper.WeChatHelperService
import com.example.accessibilityhelper.util.click
import com.example.accessibilityhelper.util.findAccessibilityNodeByShortViewId
import com.example.accessibilityhelper.util.gestureClick

class Step4SelectContact constructor(val weChatNickNames:List<String>) : Step() {

    override fun match(service: AccessibilityService, event: AccessibilityEvent): Boolean {
        return event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
                && event.className == WeChatHelperService.PAGE.CUSTOM_SERVICE_SELECT_PAGE
    }

    override fun execute(service: AccessibilityService, event: AccessibilityEvent) {
        service.rootInActiveWindow
            .findAccessibilityNodeByShortViewId("c9d")
            .firstOrNull()?.getChild(3)
            ?.findAccessibilityNodeByShortViewId("dyi")
            ?.firstOrNull()
            ?.gestureClick(service)
        service.rootInActiveWindow.findAccessibilityNodeByShortViewId("g43").firstOrNull()?.click()
        finish()
    }
}